package edu.tjhsst.androidIntranet.news;

import java.text.SimpleDateFormat;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.TextView;
import edu.tjhsst.androidIntranet.R;
import edu.tjhsst.androidIntranet.db.IntranetDbAdapter;
import edu.tjhsst.androidIntranet.db.IntranetDbAdapter.NewsDbAdapter;

public class NewsEntryViewer extends Activity {

	public void onCreate(Bundle icicle) {
		Log.d("NewsEntryViewer", "NewsEntryViewer started");
		super.onCreate(icicle);
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.news_entry_viewer);
		
		FrameLayout contentFrame = (FrameLayout) findViewById(android.R.id.content);
		//Turns off fade effect above header (just like contacts)
		contentFrame.setWillNotDraw(true);
		
		String id;
		int identifier=-1;
		if((id=getIntent().getData().getLastPathSegment())!=null) {
			identifier = Integer.parseInt(id);
		} else {
			startActivity(new Intent("android.intent.action.VIEW", new Uri.Builder().path(("content://tjIntranet/news/")).build(), this, NewsEntryPicker.class));
		}
		NewsDbAdapter nDbA = IntranetDbAdapter.getNewsDbAdapter(this);
		NewsEntry ne = nDbA.getNewsEntry(identifier);
		TextView title = (TextView) findViewById(R.id.news_entry_viewer_title);
		TextView content = (TextView) findViewById(R.id.news_entry_viewer_content);
		//TextView poster = (TextView) findViewById(R.id.news_entry_viewer_poster);
		TextView date = (TextView) findViewById(R.id.news_entry_viewer_date);
		//TODO: scrolling if the content is too long
		title.setText(ne.getTitle());
		content.setText(ne.getContent());
		//poster.setText(ne.getPoster());
		String dateText = SimpleDateFormat.getDateInstance().format(ne.getDatePosted());
		//dateText=dateText.concat("\n"+new SimpleDateFormat("h:mm a").format(ne.getDatePosted()));
		date.setText(dateText);
	}

}
